import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router';

import App from '@/App.vue';
import PodList from '@/pages/PodList.vue';
const PodDetail = () => import(/* webpackChunkName: "pod-detail" */  './../pages/PodDetail.vue');
const DeploymentList = () => import(/* webpackChunkName: "deployment" */  './../pages/DeploymentList.vue');
const DeploymentDetail = () => import(/* webpackChunkName: "deployment" */  './../pages/DeploymentDetail.vue');



const routers: RouteRecordRaw[] = [
    {
        name: 'base',
        path: '/',
        component: App,
        redirect: '/pod',
        children: [
            {
                path: 'pod',
                name: 'podList',
                component: PodList
            },
            {
                path: 'pod/:id',
                name: 'podDetail',
                component: PodDetail,
                props: true
            }
        ]
    },
    {
        name: 'deployment',
        path: '/deployment',
        component: App,
        children: [
            {
                path: '',
                name: 'deploymentList',
                component: DeploymentList
            },
            {
                path: ':id',
                name: 'deploymentDetail',
                component: DeploymentDetail,
                props: true
            }
        ]
    },
    {
        name: '404',
        path: '/:notFind(.*)',
        redirect: '/deployment'
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes: routers
});

router.beforeEach(async (to, from, next) => {
    const removeRoute = 'podDetail';
    if(router.hasRoute(removeRoute)) {
        router.removeRoute(removeRoute);
    }
    next();
});

export default router;